//
//  UIBarButtonItem+Extension.swift
//  SinaWeibo
//
//  Created by 程建 on 16/9/23.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init(title:String = "", imageName: String? = nil, target: Any?, action: Selector) {
        let leftBtn = UIButton()
        leftBtn.setTitle(title, for: UIControlState.normal)
        leftBtn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
        leftBtn.setTitleColor(UIColor.orange, for: UIControlState.highlighted)
        //设置字体
        leftBtn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        
        if imageName != nil {
            
            leftBtn.setImage(UIImage(named: imageName!), for: UIControlState.normal)
            leftBtn.setImage(UIImage(named: imageName!+"_highlighted"), for: UIControlState.highlighted)
        
        }
        leftBtn.sizeToFit()
        leftBtn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        self.init()
        self.customView = leftBtn
    }
}
